<?php
namespace App\Console\Commands\Task;

use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

use App\Repositories\Task\TaskRepository;

/**
 * 超过3天的优质任务取消优质标识
 * Class TaskOver
 * @package App\Console\Commands\TaskCancelHigh
 * @version v1.3
 */
class TaskCancelHigh extends Command
{
	protected $signature = 'task:cancelHigh';

	protected $description = 'Cancel overtime high level task';

	private $logger;


	private $taskRepository;

	public function __construct(TaskRepository $taskRepository)
	{
		parent::__construct();
		$this->logger = Log::channel('console');
		$this->taskRepository = $taskRepository;
	}

	public function handle() {
		foreach ($this->taskRepository->getOverHighTask() as $taskId) {
			try {
				$this->taskRepository->setTaskHigh($taskId, 0);
			} catch (\Exception $e) {
				$this->logger->error($this->signature, [$e->getMessage(), $taskId]);
				$this->error($e->getMessage());
			}
		}

		$this->info($this->signature . ' success！'. (new Carbon())->toDateTimeString());
	}
}